// i.d(t, { sU: () => r, uz: () => o, bf: () => a, KK: () => c })
import funcUtil from "./func.util"

import url from "url"

const initUrlConfig = (e = "", t) => {
    let urlBase: string, urlModel: string, sid: string
    if (e.match(/^https?/)) {
      const t = url.parse(e)
      urlBase = t.protocol + "//" + t.host
      urlModel = e
      sid = e.match(/[^/]*$/)![0]
    } else {
      if (t.match(/^https?/)) {
        const e = url.parse(t)
        urlBase = e.protocol + "//" + e.host
      } else urlBase = window.location.protocol + "//" + t
      urlModel = urlBase + "/api/player/models/" + e
      sid = e
    }
    return {
      sid,
      urlBase,
      urlModel,
      urlFiles: urlModel + (urlModel.match(/\/$/) ? "files" : "/files"),
      urlThumb: urlModel + (urlModel.match(/\/$/) ? "thumb" : "/thumb")
    }
  },
  getModelID = () => {
    return funcUtil.getUrlParams("model") || funcUtil.getUrlParams("m")
  },
  addParams = (e, t = {}) => {
    for (const i in t) {
      const n = t[i]
      e += (-1 === e.indexOf("?") ? "?" : "&") + `${i}=${n}`
    }
    return e
  },
  getOrigin = (e: string) => {
    let t: URL
    try {
      t = new URL(e)
    } catch (e) {
      return null
    }
    return t.origin
  }
export default {
  initUrlConfig,
  getModelID,
  addParams,
  getOrigin
}
